package com.link2room.jetfire.service.impl;

import com.link2room.common.constant.AllPmsConstant;
import com.link2room.common.constant.BaseConstant;
import com.link2room.common.constant.DefaultValue;
import com.link2room.common.dto.threadlocal.BaseThreadLocal;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.mns.MNSUtil;
import com.link2room.common.service.ICommonService;
import com.link2room.common.util.*;
import com.link2room.enums.exception.JetfireSysExceptionEnum;
import com.link2room.jetfire.constant.ReservationConstant;
import com.link2room.jetfire.constant.ReservationPromotionConstant;
import com.link2room.jetfire.dto.param.base.ReservationParamDto;
import com.link2room.jetfire.dto.result.base.*;
import com.link2room.jetfire.dto.result.extra.L2RPromotionDto;
import com.link2room.jetfire.entity.*;
import com.link2room.jetfire.exception.JetfireException;
import com.link2room.jetfire.feign.optimus.MarketingDetailFeignService;
import com.link2room.jetfire.feign.soundwave.PmsReservationFeignService;
import com.link2room.jetfire.service.IReservationService;
import com.link2room.optimus.constant.BaseRateplanConstant;
import com.link2room.optimus.constant.OptimusMnsConstant;
import com.link2room.optimus.dto.param.inside.BookStockInsideParamDto;
import com.link2room.optimus.dto.result.base.BookStockDto;
import com.link2room.optimus.dto.result.base.L2REverydayPriceAndStockDto;
import com.link2room.rodimus.constant.RodimusMnsConstant;
import com.link2room.rodimus.dto.param.base.PointBaseParamDto;
import com.link2room.soundwave.constant.SoundwaveMnsConstant;
import com.link2room.soundwave.dto.param.inside.PmsReservationPayInsideParamDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by sss on 2016/9/20.
 */
@Service("reservationService")
public class ReservationServiceImpl implements IReservationService {
    @Resource
    private ICommonService commonService;
    @Autowired
    private PmsReservationFeignService pmsReservationFeignService;
    @Autowired
    private MarketingDetailFeignService marketingDetailFeignService;
    @Resource
    private MNSUtil mnsUtil;

    static ReentrantLock reentrantLock=new ReentrantLock();

    @Override
    @Transactional
    public ReservationBase saveReservationAll(ReservationBase reservationBase,
                                              List<ReservationPrice> reservationPriceList,
                                              List<GcOrderCoupon> gcOrderCouponList,
                                              ReservationAccount reservationAccount,
                                              List<ReservationPromotion> reservationPromotionList)throws Exception{
        commonService.save(reservationBase);
        commonService.saveList(reservationPriceList);
        if(gcOrderCouponList!=null&&gcOrderCouponList.size()>0){
            commonService.saveList(gcOrderCouponList);
        }
        if(reservationPromotionList!=null&&reservationPromotionList.size()>0){
            commonService.saveList(reservationPromotionList);
        }
        commonService.save(reservationAccount);
        return reservationBase;
    }

    @Override
    public String getNo(String noType)throws Exception{
        try {
            reentrantLock.lock();
            List params=new ArrayList<>();
            params.add(noType);
            String no=commonService.findOneFieldByProcedure("create_No",params);
            return no;
        }finally {
            reentrantLock.unlock();
        }
    }

    @Override
    @Transactional
    public void saveReservationPayToPms(String lhotelGrouCode, String lhotelCode, String l2rNo,String pmsResType, ReservationPaymentDto reservationPaymentDto)throws Exception{
        ReservationPayment reservationPayment=ClassConverUtil.copyProperties(reservationPaymentDto,ReservationPayment.class);
        PmsReservationPayInsideParamDto pmsReservationPayInsideParamDto = new PmsReservationPayInsideParamDto();
        pmsReservationPayInsideParamDto.setLhotelCode(reservationPayment.getLhotelCode());
        pmsReservationPayInsideParamDto.setLhotelGroupCode(reservationPayment.getLhotelGroupCode());
        pmsReservationPayInsideParamDto.setTaNo(reservationPayment.getTaNo());
        pmsReservationPayInsideParamDto.setAmount(reservationPayment.getAmount());
        pmsReservationPayInsideParamDto.setL2RNo(reservationPayment.getL2RNo());
        pmsReservationPayInsideParamDto.setTaCode(reservationPayment.getTaCode());
        pmsReservationPayInsideParamDto.setLimitOnce(DefaultValue.F);
        pmsReservationPayInsideParamDto.setRemark(reservationPayment.getRemark());
        pmsReservationPayInsideParamDto.setPmsResType(pmsResType);
        ReservationAccount queryRA=new ReservationAccount();
        queryRA.setLhotelGroupCode(lhotelGrouCode);
        queryRA.setLhotelCode(lhotelCode);
        queryRA.setL2RNo(l2rNo);
        ReservationAccount reservationAccount=commonService.findOneEQ(ReservationAccount.class,queryRA);
        try {
            pmsReservationFeignService.saveReservationPay(pmsReservationPayInsideParamDto);
            reservationPayment.setPmsPaysta(ReservationConstant.PMSPAYSTA.DONE);
            reservationAccount.setSavepayMoney(reservationAccount.getSavepayMoney().add(reservationPayment.getAmount()));
            if(ReservationConstant.L2RPAYSTA.DONE.equals(reservationAccount.getL2rPaysta())
                    &&reservationAccount.getDeposit().compareTo(reservationAccount.getSavepayMoney())==0){
                reservationAccount.setPmsPaysta(ReservationConstant.PMSPAYSTA.DONE);
            }
        }catch (Exception e){
            if(ReservationConstant.L2RPAYSTA.DONE.equals(reservationAccount.getL2rPaysta())
                    &&reservationAccount.getDeposit().compareTo(reservationAccount.getSavepayMoney())==0){
                reservationAccount.setPmsPaysta(ReservationConstant.PMSPAYSTA.FAIL);
            }
            reservationPayment.setPmsPaysta(ReservationConstant.PMSPAYSTA.FAIL);
            throw e;
        }finally {
            commonService.merge(reservationAccount);
            commonService.updateById(reservationPayment);
        }

    }

    @Override
    public ReservationDto createReservation(ReservationParamDto reservationParamDto)throws Exception{
        ReservationBaseDto reservationBaseDto = reservationParamDto.getReservationBase();
        L2RAssert.stringBlank(reservationBaseDto.getArrtime(),"到店日期缺失");
        L2RAssert.stringBlank(reservationBaseDto.getDeptime(),"离店日期缺失");
        if(DateUtil.getWebDateString(reservationBaseDto.getArr()).equals(DateUtil.getWebDateString(reservationBaseDto.getDep()))){
            throw new JetfireException(JetfireSysExceptionEnum.RESER_SAVE_ERROR,"到店日期与离店日期不能为同一天");
        }
        String l2rNo=this.getNo("L2RNo");
        //再次可定检查
        BookStockInsideParamDto bookStockInsideParamDto =new BookStockInsideParamDto();
        bookStockInsideParamDto.setLhotelGroupCode(reservationBaseDto.getLhotelGroupCode());
        bookStockInsideParamDto.setLhotelCode(reservationBaseDto.getLhotelCode());
        bookStockInsideParamDto.setCheckInDatetime(reservationBaseDto.getArrtime());
        bookStockInsideParamDto.setCheckOutDatetime(reservationBaseDto.getDeptime());
        bookStockInsideParamDto.setRmNum(reservationBaseDto.getRoomNum());
        bookStockInsideParamDto.setMcdCode(reservationBaseDto.getMcdCode());
        bookStockInsideParamDto.setMemberLevel(reservationParamDto.getMemberLevel());
        bookStockInsideParamDto.setPbChannel(reservationBaseDto.getPbChannel());
        bookStockInsideParamDto.setIsUsePoint(reservationBaseDto.getIsUsePoint());
        BookStockDto bookStock = marketingDetailFeignService.bookStocks(bookStockInsideParamDto.paramToMap()).getResultInfo();
        /*if(BaseConstant.PbChannelConstant.TAOBAO.equals(reservationBaseDto.getPbChannel())){
            this.checkPrice(bookStock.getL2REverydayPriceAndStockDtoList(),reservationInsideParamDto.getReservationPriceDtos());
        }*/
        //每日房价+房间校验
        List<ReservationPrice> reservationPrices=new ArrayList<>();
        for(L2REverydayPriceAndStockDto everyPrice:bookStock.getL2REverydayPriceAndStockDtoList()){
            if(reservationParamDto.getReservationPriceDtos()!=null){
                for(ReservationPriceDto reservationPrice: reservationParamDto.getReservationPriceDtos()){
                    if(DateUtil.format(reservationPrice.getResDate(),DateUtil.webFormat).equals(DateUtil.format(everyPrice.getRsvDate(),DateUtil.webFormat))){
                        if(reservationPrice.getAmountSale().compareTo(everyPrice.getL2REverydayPriceDto().getCurrentPrice())!=0){
                            throw new JetfireException(JetfireSysExceptionEnum.PRICE_NOT_MATCH);
                        }
                    }
                }
            }
            //TODO 如果使用我们的酒店出钱电子券需要重构每日房价
            ReservationPrice reservationPrice=new ReservationPrice();
            reservationPrice.setLhotelGroupCode(reservationBaseDto.getLhotelGroupCode());
            reservationPrice.setLhotelCode(reservationBaseDto.getLhotelCode());
            reservationPrice.setMcCode(reservationBaseDto.getMcCode());
            reservationPrice.setL2RNo(l2rNo);
            reservationPrice.setAmountBase(everyPrice.getL2REverydayPriceDto().getBasePrice());
            reservationPrice.setAmountCost(everyPrice.getL2REverydayPriceDto().getCostPrice());
            reservationPrice.setAmountSale(everyPrice.getL2REverydayPriceDto().getCurrentPrice());
            reservationPrice.setAmountPms(everyPrice.getL2REverydayPriceDto().getPmsPrice());
            reservationPrice.setRateType(ReservationConstant.RATETYPE.ROOM);
            reservationPrice.setResDate(DateUtil.parseDateNewFormat(everyPrice.getRsvDatetime()));
            reservationPrice.setRoomtype(bookStock.getRmtype());
            reservationPrices.add(reservationPrice);
        }
        //房量检验
        Integer rmNum= reservationBaseDto.getRoomNum();
        if(bookStock==null||bookStock.getMinSaleNum()<rmNum||"F".equals(bookStock.getIsBookable())){
            throw new JetfireException(JetfireSysExceptionEnum.RESER_RMNUM_LESS);
        }

        //OTA订单查重
        if(StringUtil.isNotBlank(reservationBaseDto.getTerminalNo())){
            ReservationBase queryRb=new ReservationBase();
            queryRb.setLhotelGroupCode(reservationBaseDto.getLhotelGroupCode());
            queryRb.setLhotelCode(reservationBaseDto.getLhotelCode());
            queryRb.setTerminalNo(reservationBaseDto.getTerminalNo());
            ReservationBase reservationBase=commonService.findOneEQ(ReservationBase.class,queryRb);
            if(reservationBase!=null){
                throw new JetfireException(JetfireSysExceptionEnum.RESER_IS_EXIST);
            }
        }

        //订单基础
        ReservationBase reservationBase= ClassConverUtil.copyProperties(reservationBaseDto,ReservationBase.class);
        reservationBase.setAmount(bookStock.getTotalPriceSale());
        reservationBase.setMemberNo(reservationBaseDto.getMemberNo());
        reservationBase.setMemberLevel(reservationParamDto.getMemberLevel());
        reservationBase.setOpenid(reservationBaseDto.getOpenid());
        reservationBase.setConfirmSta(ReservationConstant.CONFIRMSTA.NOTCFMD);
        reservationBase.setResSta(ReservationConstant.RESSTA.R);
        reservationBase.setResType(bookStock.getResType());
        reservationBase.setPmsRatecode(bookStock.getPmsRatecode());
        reservationBase.setL2RNo(l2rNo);
        reservationBase.setRmtype(bookStock.getRmtype());
        reservationBase.setRmtypeName(bookStock.getRmtypeName());
        reservationBase.setRmtypeNameEn(bookStock.getRmtypeNameEn());
        reservationBase.setHotelName(bookStock.getHotelName());
        reservationBase.setHotelNameEn(bookStock.getHotelNameEn());
        reservationBase.setMcdName(bookStock.getMcdName());
        reservationBase.setMcdNameEn(bookStock.getMcdNameEn());
        reservationBase.setStayNum(DateUtil.dateNum(reservationBaseDto.getArr(),reservationBaseDto.getDep()));
        reservationBase.setIsToPms(bookStock.getIsToPms());
        //官网和微信保存取消政策
        if(bookStock.getL2RRateplan()!=null){
            reservationBase.setCancelType(bookStock.getL2RRateplan().getCancelType());
            reservationBase.setCancelRule(bookStock.getL2RRateplan().getCancelRule());
        }else {
            reservationBase.setCancelType(BaseRateplanConstant.CANCELTYPE.ALLOW);
        }
        //订单账务
        ReservationAccount reservationAccount=ClassConverUtil.copyProperties(reservationBase,ReservationAccount.class);
        reservationAccount.init();
        reservationAccount.setL2RNo(l2rNo);
        reservationAccount.setResRateSumCost(bookStock.getTotalPriceCost());
        reservationAccount.setResRateRoomCost(bookStock.getTotalPriceCost());
        reservationAccount.setResRateSumSale(bookStock.getTotalPriceSale());
        reservationAccount.setResRateRoomSale(bookStock.getTotalPriceSale());
        reservationAccount.setResRateSumPms(bookStock.getTotalPricePms());
        reservationAccount.setResRateRoomPms(bookStock.getTotalPricePms());
        reservationAccount.setComm(bookStock.getComm());
        reservationAccount.setCommCode(bookStock.getCommCode());
        //订单优惠信息记录
        List<ReservationPromotion> reservationPromotions=new ArrayList<>();

        //判断是否使用积分
        if(StringUtil.isNotBlank(reservationBaseDto.getIsUsePoint())&& DefaultValue.T.equals(reservationBaseDto.getIsUsePoint())){
            if(StringUtil.isNotBlank(bookStock.getCanUsePoint())&&DefaultValue.T.equals(bookStock.getCanUsePoint())){
                reservationAccount.setL2RPromotion(bookStock.getPointToMoney());
                L2RPromotionDto l2RPromotionDto=new L2RPromotionDto();
                l2RPromotionDto.setTaCode(bookStock.getPointPayTaCode());
                ReservationPromotion reservationPromotion=new ReservationPromotion();
                reservationPromotion.setLhotelGroupCode(reservationBaseDto.getLhotelGroupCode());
                reservationPromotion.setLhotelCode(reservationBaseDto.getLhotelCode());
                reservationPromotion.setL2RNo(l2rNo);
                reservationPromotion.setPromotionType(ReservationPromotionConstant.PROMOTIONTYPE.POINT);
                reservationPromotion.setPromotionValue(new BigDecimal(bookStock.getUsePoint()));
                reservationPromotion.setAmount(bookStock.getPointToMoney());
                reservationPromotion.setDescript("积分抵现");
                reservationPromotion.setPromotionCode(bookStock.getL2RRateplan().getPointRule());
                reservationPromotion.setExtend(JacksonUtil.beanToJson(l2RPromotionDto));
                reservationPromotions.add(reservationPromotion);
            }else {
                throw new JetfireException(JetfireSysExceptionEnum.POINT_USE_ERROR);
            }
        }

        //电子券
        List<GcOrderCoupon> gcOrderCoupons=null;
        BigDecimal couponValue=new BigDecimal(0);
        boolean flag=false;
        if(reservationParamDto.getGcOrderCoupons()!=null&& reservationParamDto.getGcOrderCoupons().size()>0){
            gcOrderCoupons=ClassConverUtil.copyPropertiesList(reservationParamDto.getGcOrderCoupons(),GcOrderCoupon.class);
            for(GcOrderCoupon gcOrderCoupon:gcOrderCoupons){
                ReservationPromotion reservationPromotion=new ReservationPromotion();
                reservationPromotion.setLhotelGroupCode(reservationBaseDto.getLhotelGroupCode());
                reservationPromotion.setLhotelCode(reservationBaseDto.getLhotelCode());
                reservationPromotion.setL2RNo(l2rNo);
                String pmsType= SysoptionUtil.getSysOption(BaseThreadLocal.getLhotelGroupCode(), AllPmsConstant.CONFIG_CATEGORY,AllPmsConstant.CONFIG_ITEM.PMSTYPE);

                String promotionType= Optional.ofNullable(pmsType).map(value->{
                    if(AllPmsConstant.PMSTYPE.GCPMS.equals(value)){
                        return ReservationPromotionConstant.PROMOTIONTYPE.GCCOUPON;
                    }else if(AllPmsConstant.PMSTYPE.YHPMS.equals(value)){
                        return ReservationPromotionConstant.PROMOTIONTYPE.YHCOUPON;
                    }else {
                        return ReservationPromotionConstant.PROMOTIONTYPE.L2RCOUPON;
                    }
                }).orElse(ReservationPromotionConstant.PROMOTIONTYPE.L2RCOUPON);

                reservationPromotion.setPromotionType(promotionType);
                reservationPromotion.setPromotionValue(new BigDecimal(gcOrderCoupon.getPresentValue()));
                reservationPromotion.setAmount(new BigDecimal(gcOrderCoupon.getPresentValue()));
                reservationPromotion.setDescript(gcOrderCoupon.getCouponName());
                reservationPromotion.setPromotionCode(gcOrderCoupon.getCouponCode());
                reservationPromotion.setPromotionNo(gcOrderCoupon.getCouponNo());
                reservationPromotion.setExtend(new HashMap<String,String>().put("couponType",gcOrderCoupon.getCouponType()));
                couponValue=couponValue.add(new BigDecimal(gcOrderCoupon.getPresentValue()));
                //RF为绿云免费房券，3为昱恒免房券
                if("RF".equals(gcOrderCoupon.getCouponType())||"3".equals(gcOrderCoupon.getCouponType())){
                    flag=true;
                    reservationPromotion.setAmount(reservationAccount.getResRateSumSale().subtract(reservationAccount.getL2RPromotion()));
                }
                gcOrderCoupon.setLhotelGroupCode(reservationBaseDto.getLhotelGroupCode());
                gcOrderCoupon.setL2RNo(l2rNo);
                gcOrderCoupon.setLhotelCode(reservationBaseDto.getLhotelCode());
                reservationPromotions.add(reservationPromotion);
            }
            reservationAccount.setHotelPromotion(reservationAccount.getHotelPromotion().add(couponValue));
        }
        //如果客人使用了免房券，需要支付金额为0
        if(flag){
            reservationAccount.setHotelPromotion(reservationAccount.getResRateSumSale().subtract(reservationAccount.getL2RPromotion()));
            reservationAccount.setResRatePaySale(new BigDecimal(0));
        }else {
            reservationAccount.setResRatePaySale(reservationAccount.getResRateSumSale().subtract(reservationAccount.getL2RPromotion()).subtract(reservationAccount.getHotelPromotion()));
        }
        if(BaseRateplanConstant.RESTYPE.PRE.equals(bookStock.getResType())&&
                (BaseConstant.PbChannelConstant.WEB.equals(reservationBaseDto.getPbChannel())
                        ||BaseConstant.PbChannelConstant.WECHAT.equals(reservationBaseDto.getPbChannel()))
                ){
            reservationBase.setCancelDate(DateUtil.addMinutes(new Date(),bookStock.getL2RRateplan().getPayTime()));
        }

        reservationAccount.setResRatePromotionShow(reservationAccount.getL2RPromotion().add(reservationAccount.getHotelPromotion()));
        reservationBase= this.saveReservationAll(reservationBase, reservationPrices,gcOrderCoupons, reservationAccount, reservationPromotions);

        if(reservationBase.getId()!=null){
            ReservationBaseDto reservationBaseDtoNew=ClassConverUtil.copyPropertiesToDto(reservationBase,ReservationBaseDto.class,false);
            List<ReservationPriceDto> priceDtoList=ClassConverUtil.copyPropertiesListToDtoList(reservationPrices,ReservationPriceDto.class,false);
            List<GcOrderCouponDto> gcOrderCouponsList=ClassConverUtil.copyPropertiesListToDtoList(gcOrderCoupons, GcOrderCouponDto.class,false);
            ReservationDto reservationDto=new ReservationDto();
            reservationDto.setReservationBaseDto(reservationBaseDtoNew);
            reservationDto.setReservationPriceDtos(priceDtoList);
            reservationDto.setGcOrderCouponDtos(gcOrderCouponsList);
            reservationDto.setReservationPromotionDtos(ClassConverUtil.copyPropertiesListToDtoList(reservationPromotions,ReservationPromotionDto.class,false));
            return reservationDto;
        }else {
            throw new JetfireException(JetfireSysExceptionEnum.RESER_SAVE_ERROR);
        }
    }

    @Override
    public void saveReservationNmsSta(String lhotelGroupCode,
                                      String lhotelCode,
                                      String l2rNo,
                                      String item,
                                      String operSta,
                                      String operType)throws Exception{
        ReservationNmsSta reservationNmsSta=new ReservationNmsSta();
        reservationNmsSta.setLhotelGroupCode(lhotelGroupCode);
        reservationNmsSta.setLhotelCode(lhotelCode);
        reservationNmsSta.setL2RNo(l2rNo);
        reservationNmsSta.setOperSta(operSta);
        reservationNmsSta.setItem(item);
        reservationNmsSta.setOperType(operType);
        commonService.save(reservationNmsSta);
    }

    @Override
    public void cancelReservation(ReservationBase reservationBase)throws Exception{
        reservationBase.setConfirmSta(ReservationConstant.CONFIRMSTA.CANCELING);
        reservationBase.setRealCancelDate(new Date());
        commonService.merge(reservationBase);

        ReservationNmsSta reservationNmsSta2 = new ReservationNmsSta();
        reservationNmsSta2.setLhotelGroupCode(reservationBase.getLhotelGroupCode());
        reservationNmsSta2.setLhotelCode(reservationBase.getLhotelCode());
        reservationNmsSta2.setL2RNo(reservationBase.getL2RNo());
        reservationNmsSta2.setItem(BaseConstant.ServiceCategoryConstant.OPTIMUS);
        reservationNmsSta2.setOperType(ReservationConstant.OPERTYPE.CANCEL);
        commonService.save(reservationNmsSta2);

        ReservationParamDto reservationInsideParamDto = new ReservationParamDto();
        reservationInsideParamDto.setOperType(ReservationConstant.OPERTYPE.CANCEL);
        reservationInsideParamDto.setReservationBase(ClassConverUtil.copyPropertiesToDto(reservationBase, ReservationBaseDto.class, false));

        if (ReservationConstant.RESSTA.R.equals(reservationBase.getResSta())) {
            if(DefaultValue.T.equals(reservationBase.getIsToPms())) {
                ReservationNmsSta reservationNmsSta = new ReservationNmsSta();
                reservationNmsSta.setLhotelGroupCode(reservationBase.getLhotelGroupCode());
                reservationNmsSta.setLhotelCode(reservationBase.getLhotelCode());
                reservationNmsSta.setL2RNo(reservationBase.getL2RNo());
                reservationNmsSta.setItem(BaseConstant.ServiceCategoryConstant.SOUNDWAVE);
                reservationNmsSta.setOperType(ReservationConstant.OPERTYPE.CANCEL);
                commonService.save(reservationNmsSta);
                mnsUtil.putMessageToQueue(SoundwaveMnsConstant.QUEUE_ORDER_SOUNDWAVE, JacksonUtil.beanToJson(reservationInsideParamDto));
            }
        }
        ReservationNmsSta queryNms=new ReservationNmsSta();
        queryNms.setLhotelGroupCode(reservationBase.getLhotelGroupCode());
        queryNms.setLhotelCode(reservationBase.getLhotelCode());
        queryNms.setL2RNo(reservationBase.getL2RNo());
        queryNms.setItem(BaseConstant.ServiceCategoryConstant.RODIMUS);
        queryNms.setOperType(ReservationConstant.OPERTYPE.CREATE);
        queryNms.setOperSta(DefaultValue.T);
        ReservationNmsSta rns = commonService.findOneEQ(ReservationNmsSta.class, queryNms);
        if(rns!=null){
            ReservationNmsSta reservationNmsSta = new ReservationNmsSta();
            reservationNmsSta.setLhotelGroupCode(reservationBase.getLhotelGroupCode());
            reservationNmsSta.setLhotelCode(reservationBase.getLhotelCode());
            reservationNmsSta.setL2RNo(reservationBase.getL2RNo());
            reservationNmsSta.setItem(BaseConstant.ServiceCategoryConstant.RODIMUS);
            reservationNmsSta.setOperType(ReservationConstant.OPERTYPE.CANCEL);
            commonService.save(reservationNmsSta);
            ReservationPromotion queryRE=new ReservationPromotion();
            queryRE.setLhotelGroupCode(reservationBase.getLhotelGroupCode());
            queryRE.setLhotelCode(reservationBase.getLhotelCode());
            queryRE.setL2RNo(reservationBase.getL2RNo());
            QueryResult<ReservationPromotion> reservationPromotionQueryResult=commonService.findAllEQ(ReservationPromotion.class,queryRE);
            if(reservationPromotionQueryResult.getResultlist()!=null){
                for(ReservationPromotion l2rPromotion:reservationPromotionQueryResult.getResultlist()){
                    if(ReservationConstant.PromotionType.POINT.equals(l2rPromotion.getPromotionType())&&!DefaultValue.NONE.equals(l2rPromotion.getPromotionCode())){
                        PointBaseParamDto pointBaseParamDto=new PointBaseParamDto();
                        pointBaseParamDto.setPoint(l2rPromotion.getPromotionValue());
                        pointBaseParamDto.setL2RNo(reservationBase.getL2RNo());
                        pointBaseParamDto.setLhotelCode(reservationBase.getLhotelCode());
                        pointBaseParamDto.setOperType(ReservationConstant.OPERTYPE.REVERT);
                        pointBaseParamDto.setPointToMoney(l2rPromotion.getAmount());
                        pointBaseParamDto.setL2rMemberNo(reservationBase.getMemberNo());
                        if(StringUtil.isNotBlank(l2rPromotion.getExtend())){
                            pointBaseParamDto.setTaCode(JacksonUtil.jsonToBean(l2rPromotion.getExtend(),L2RPromotionDto.class).getTaCode());
                        }
                        mnsUtil.putMessageToQueue(RodimusMnsConstant.QUEUE_ORDER_POINT_RODIMUS,JacksonUtil.beanToJson(pointBaseParamDto));
                    }
                }
            }
        }

        mnsUtil.putMessageToQueue(OptimusMnsConstant.QUEUE_ORDER_OPTIMUS, JacksonUtil.beanToJson(reservationInsideParamDto));
    }

}
